﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace Demos.ShortestPaths.Dijkstra
{
    /// <summary>
    /// Interaction logic for EditarElemento.xaml
    /// </summary>
    public partial class EditarElemento : Window
    {
        public delegate void ElementoModificadoHandler(string c, object o);
        public event ElementoModificadoHandler ElementoModificado;
        private readonly object _sender;

        public EditarElemento(object sender)
        {
            InitializeComponent();
            contenidoTxt.Text = (string)((Label) sender).Content;
            _sender = sender;

            //asociar futuro comando aceptar
            var returnKb = new KeyBinding(ApplicationCommands.NotACommand,Key.Return,ModifierKeys.None);
            InputBindings.Add(returnKb);
        }

        private void AceptarEdicionClick(object sender, RoutedEventArgs e)
        {
            Label l = _sender as Label;
            l.Content = contenidoTxt.Text;
            ElementoModificado(contenidoTxt.Text, _sender);
            Close();
        }

        private void CancelarEdicionClick(object sender, RoutedEventArgs e)
        {
            Close();
        }
    }
}
